package pers.cz.jefconfig.reader;

import pers.cz.jefconfig.reader.xml.XmlReader;
import pers.cz.jefconfig.reader.yaml.YamlReader;
import pers.cz.jefconfig.reader.properties.PropertiesReader;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: JefConfig
 * @description: 文件reader工厂
 * @author: Cheng Zhi
 * @create: 2023-04-10 09:47
 **/
public class ReaderFactory {

    private static Map<FileType, Reader> readerMap = new HashMap<FileType, Reader>();

    static {
        // 注册reader
        readerRegist();
    }

    public static void readerRegist() {
        readerMap.put(FileType.PROPERTIES, new PropertiesReader());
        readerMap.put(FileType.YMAL, new YamlReader());
        readerMap.put(FileType.XML, new XmlReader());
    }

    public static Reader getReader(FileType fileType) {

        Reader reader = readerMap.get(fileType);
        if (reader == null) {
            throw new RuntimeException("不支持的文件类型");
        }
        return reader;
    }
}
